package heven.holt.wan.android.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import heven.holt.wan.android.api.ApiWanProjectServer
import heven.holt.wan.android.paging.source.WanArticleProjectHomePagingSource

class WanProjectRepository(
    private val apiWanProjectServer: ApiWanProjectServer
) {
    companion object {
        private const val PAGE_SIZE = 20
    }

    suspend fun getProjectTree() = apiWanProjectServer.getProjectTree()

    /**
     * 获取知识体系下的文章列表
     */
    fun getArticleProjectListFlow(cid: Int) = Pager(
        config = PagingConfig(
            initialLoadSize = 10,
            prefetchDistance = 5,
            enablePlaceholders = false,
            pageSize = PAGE_SIZE
        )
    ) {
        WanArticleProjectHomePagingSource(apiWanProjectServer, cid)
    }.flow
}